package com.chench.ai.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatRoleController {

    @Resource
    private ChatClient chatClient;

//    public ChatRoleController(ChatClient.Builder clientBuilder) {
//        this.chatClient = clientBuilder.defaultSystem("我是陈朝虎，我是一个来自农村的哇哇。").build();
//    }

    @GetMapping("/promptRole")
    public String promptRole(@RequestParam(value = "msg", defaultValue = "请问，你是谁？") String message) {
        return chatClient.prompt()//提示词
                .user(message)//用户输入内容
                .call()//请求大模型
                .content();// 返回结果文本

    }

    @GetMapping(value = "/promptRoleStream", produces = "text/html;charset=UTF-8")
    public Flux<String> promptRoleStream(@RequestParam(value = "msg", defaultValue = "请问，你是谁？") String message) {
        return chatClient.prompt()//提示词
                .user(message)//用户输入内容
                .stream()//请求大模型
                .content();// 返回结果文本

    }
}
